function fictionUpdateShowPostFictionInfo(info) {
    var parent = $('#post-fiction-result');
    info = '<li>' + info + '</li>';
    parent.append(info);
}

/**
 * 检测内容，如果内容符合，则提交新的文章
 */
function fictionUpdateOnFinishFictionClick() {
    var fictionid = $('#fiction-id-container').attr('value');

    var titleHandle = $('#fiction-title');
    var title = titleHandle.val();

    var descriptionHandle = $('#fiction-description');
    var description = descriptionHandle.val();

    var authorHandle = $('#fiction-author');
    var author = authorHandle.val();

    var finishYearHandle = $('#fiction-finish-year');
    var finishYear = finishYearHandle.val();

    var finished = $('#fiction-finished-checkbox').is(':checked');

    var token = getCookie("token");

    if (fictionid == undefined || fictionid == null || fictionid == '') {
        fictionUpdateShowPostFictionInfo('<strong>' + title + '</strong>' + '提交失败！' + '原因：没有合格的目标文章ID');
        return;
    }

    if (token == undefined || token == null ) {
        fictionUpdateShowPostFictionInfo('<strong>' + title + '</strong>' + '提交失败！' + '原因：未找到用户身份证明');
        return;
    }

    if (title == undefined || title == '') {
        fictionUpdateShowPostFictionInfo('<strong>題目不能為空</strong>');
        return;
    }

    if (description == undefined || description == '') {
        fictionUpdateShowPostFictionInfo('<strong>內容不能為空</strong>');
        return;
    }

    if (finished && (finishYear == undefined || finishYear == '')) {
        fictionUpdateShowPostFictionInfo('<strong>完本年代不能為空</strong>');
        return;
    }

    if (finished && finishYear.length != 4) {
        fictionUpdateShowPostFictionInfo('<strong>完本年代必須是4個字長度</strong>');
        return;
    }

    if (finished && !isAllDigit(finishYear)) {
        fictionUpdateShowPostFictionInfo('<strong>完本年代必須是4個數字</strong>');
        return;
    }

    $.ajax(
        {
            type: 'post',
            async: true,
            data: {
                'fictionid': fictionid,
                'title': title,
                'description': description,
                'author': author,
                'finished': finished,
                'finishyear': finishYear
            },
            url: document.location.origin + '/api/updatefiction',
            dataType:'text',
            success: function(data) {
                var json = JSON.parse(data);

                if (json.result == 200) {
                    fictionUpdateShowPostFictionInfo('<strong>' + title + '</strong>' + '更新成功！' + ' ' + json.createtime);
                }
                else {
                    fictionUpdateShowPostFictionInfo('<strong>' + title + '</strong>' + '更新失败！' + '原因：' + json.description  + ' ' + json.createtime);
                }
            },
            error: function () {
                console.log("Ajax 发生错误！");
            }
        }
    );
}